<?php
/**
 * 用户管理
 * @copyright (c) Seer All Rights Reserved
 */

require_once 'globals.php';

$Wx_Push_Model = new Wx_Push_Model();

$mode = $_POST['mode'];
$pic_type = array('gif', 'jpg', 'jpeg','png');
// 优惠卡信息编辑

	$ID = $_POST['ID'];

	// 编辑画面初期化
	if(!$mode)
	{
		$wxPush=$Wx_Push_Model->getWxPushForUpdate(1);

		include View::getView('header');
		require_once View::getView('wx/wx_push_update');
		include View::getView('footer');
		View::output();
	}
	// 编辑信息提交
	else if($mode=="commit")
	{
		$title = $_POST['title'];
		$description = $_POST['description'];
		$activity_id = $_POST['activity_id'];
		$ID = $_POST['ID']?"1":"1";
		// $description = $_POST['description'];

		$prePicUrl = $_POST['pre_picurl'];
		$pre_url = $_POST['pre_url'];
		$url=$activity_id?"http://".$_SERVER['HTTP_HOST']."/m/activity/jqhd.php?activity_id=".$activity_id:$pre_url;

		if ($_FILES['picurl']['size'] > 0) {

			$imgSize=getimagesize($_FILES['picurl']['tmp_name']);
			if($imgSize[0]!=760 || $imgSize[1]!=440)
			{
				emMsg("缩略图图片尺寸错误。上传图片的尺寸：".$imgSize[0]."px*".$imgSize[1]."px，正确的尺寸：760px*440px");
				exit;
			}

			$file_info = uploadFile($_FILES['picurl']['name'], $_FILES['picurl']['error'], $_FILES['picurl']['tmp_name'], $_FILES['picurl']['size'], $pic_type, false);
			if (!empty($file_info['file_path'])) {
				$picurl = $file_info['file_path'];
			}
			$picurl="http://".$_SERVER['HTTP_HOST']."/m/".$picurl;
		}
		else
		{
			$picurl	=$prePicUrl;
		}
		$wxPush = array(
			'ID'=>$ID,
			'title' => $title,
			'description' => $description,
			'picurl' => $picurl,
			'url' => $url,
		);

		$Wx_Push_Model->editWxPush($wxPush);
		seerDirect("./wx_push_set.php?active_update=1");
	}

